/**
 * 
 */
package it.unibz.easytravel.expenses.test;



import java.util.Vector;

import it.unibz.easytravel.common.Person;
import it.unibz.easytravel.db.*;
import it.unibz.easytravel.expenses.AddExpense;
import it.unibz.easytravel.expenses.Expense;
import it.unibz.easytravel.expenses.statistic.Converter;
import it.unibz.easytravel.expenses.statistic.Statistic;

import org.junit.Before;
import org.junit.Test;

import android.app.Activity;
import android.database.Cursor;
import junit.framework.TestCase;


/**
 * @author Tadas
 * This test class is meant to test the correctness of calculations of depths 
 * of three-graph nodes
 */
public class TreeGraph extends TestCase{

	private TravellersDbAdapter mTravelersDb;
	
	private static final String INSERT_USER1 = "insert into travelers (travel_id, name, me, money_flow) values (1, 'Valdemaras', 1, 0);";
    private static final String INSERT_USER2 = "insert into travelers (travel_id, name, me, money_flow) values (1, 'Saras', 0, 0)";
    private static final String INSERT_USER3 = "insert into travelers (travel_id, name, me, money_flow) values (1, 'Marius', 0, 0)";
    private static final String INSERT_USER4 = "insert into travelers (travel_id, name, me, money_flow) values (1, 'Guoda', 0, 0)";
    private static final String INSERT_USER5 = "insert into travelers (travel_id, name, me, money_flow) values (1, 'Minde', 0, 0)";
    private static final String INSERT_USER6 = "insert into travelers (travel_id, name, me, money_flow) values (1, 'Tadas', 0, 0)";   
	
	@Test
	public void testConvert() {
		assertEquals(123400, Converter.convertToIntSplit("12.34"));
		assertEquals(123000, Converter.convertToIntSplit("12.3"));
		assertEquals(120000, Converter.convertToIntSplit("12"));
		assertEquals(3400, Converter.convertToIntSplit("0.34"));
		assertEquals(3000, Converter.convertToIntSplit("0.3"));
		assertEquals(3400, Converter.convertToIntSplit(".34"));
		assertEquals(3000, Converter.convertToIntSplit(".3"));
		
		assertEquals(12.34, Converter.convertToFloatMerge(123400),0.001);
		assertEquals(12.3, Converter.convertToFloatMerge(123000),0.001);
		assertEquals(12, Converter.convertToFloatMerge(120000),0.001);
		assertEquals(0.34, Converter.convertToFloatMerge(3400),0.001);
		assertEquals(0.3, Converter.convertToFloatMerge(3000),0.001);
		assertEquals(0.34, Converter.convertToFloatMerge(3400),0.001);
		assertEquals(0.3, Converter.convertToFloatMerge(3000),0.001);
		assertEquals(-12.34, Converter.convertToFloatMerge(-123400),0.001);
		
		assertEquals("-66.66", Converter.convertToStringMerge(-666666));
		assertEquals("-33.33", Converter.convertToStringMerge(-333333));
		assertEquals("66.66", Converter.convertToStringMerge(666666));
		assertEquals("-99.99", Converter.convertToStringMerge(-999999));
		assertEquals("12.34", Converter.convertToStringMerge(123400));
		assertEquals("12.30", Converter.convertToStringMerge(123000));
		assertEquals("12.00", Converter.convertToStringMerge(120000));
		assertEquals("0.34", Converter.convertToStringMerge(3400));
		assertEquals("0.30", Converter.convertToStringMerge(3000));
		assertEquals("0.34", Converter.convertToStringMerge(3400));
		assertEquals("0.30", Converter.convertToStringMerge(3000));
		assertEquals("-12.34", Converter.convertToStringMerge(-123400));

	}
	
	/**
	 * TODO
	 */
	@Test
	public void testAddExpenseTravelerBalanceOnAdd() {
		
		//data inicialization
		int creditor = 1;
		Vector debtors = new Vector();
		debtors.addElement(1);
		debtors.addElement(2);
		debtors.addElement(3);
		int amount = 1000000;
		
		testAddExpenseTravelerBalanceOnAdd_helper(creditor,debtors,amount);
		

	}
	
	/**
	 * testAddExpenseTravelerBalanceOnAdd() helper
	 */
	private void testAddExpenseTravelerBalanceOnAdd_helper(int creditor, Vector debtors, int amnt) {
//		//database creation
//		//add exec tavelers inicialization >>INSERT_USER1
//		AddExpense activity = new AddExpense();
//		mTravelersDb = new TravellersDbAdapter(activity);
//		mTravelersDb.open();
//		
//		//add expense
//		activity.addAmountsSpentForExpense(1, creditor, debtors, amnt);
//		
//		//check for validity
//		
//		Cursor travelersCursor = mTravelersDb.getTravellers(1);
//		int credit = 0, debit = 0;
//		
//		while (travelersCursor.moveToNext()) {
//			int moneyFlow = travelersCursor.getInt(travelersCursor.getColumnIndexOrThrow("money_flow"));
//			if (moneyFlow > 0){
//				credit += moneyFlow;
//			}else{
//				debit -= moneyFlow;
//			}
//		}
//		assertEquals(credit, -debit);
//		
//		//clean db;
//		mTravelersDb.delete();
//		mTravelersDb.close();
//		
	}

	/**
	 * TODO
	 */
	@Test
	public void testAddExpenseTravelerBalanceOnDelete() {
		
	}

	/**
	 * TODO
	 */
	@Test
	public void testAddExpenseDebtsBalanceWithTravelersOnAdd(){
		
	}
	
	/**
	 * TODO
	 */
	@Test
	public void testAddExpenseDebtsBalanceWithTravelersOnDelete() {
		
	}
	
	/**
	 * TODO
	 */
	@Test
	public void testAddExpenseDebtsBalanceWithTravelersAfteroptimization() {
		
	}
	
}
